//package com.itcast.activiti.event.listener;
//
//import com.alibaba.fastjson.JSONObject;
//import com.itcast.activiti.event.TaskAuditWarnEvent;
//import com.itcast.activiti.service.IActIdUserService;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.rocketmq.spring.core.RocketMQTemplate;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.event.EventListener;
//import org.springframework.stereotype.Component;
//import org.springframework.util.Assert;
//
//import java.util.Set;
//
///**
// * 任务审批提醒
// */
//@Slf4j
//@Component
//public class TaskAuditWarnListener {
//    @Autowired
//    private RocketMQTemplate rocketMQTemplate;
//    @Autowired
//    private IActIdUserService iActIdUserService;
//    @Value("${activiti.rocketmq.topic.activiti}")
//    private String topic;
//    @Value("${enterprise.message.switch}")
//    private boolean messageSwitch;
//
//    @EventListener
//    public void execute(TaskAuditWarnEvent event) {
//        log.info("TaskAuditWarnListener {}", JSONObject.toJSON(event));
//        if (!messageSwitch) {
//            return;
//        }
//        try {
//            String processDefinitionKey = event.getProcessDefinitionKey();
//            String email = event.getEmail();
//            String processName = event.getProcessName();
//            Set<String> accounts = iActIdUserService.accountEmails(processDefinitionKey, email, null, 0);
//            Assert.hasText(email, "email is null");
//            JSONObject jsonObject = new JSONObject();
//            jsonObject.put("email", accounts);
//            jsonObject.put("content", "审批提醒\n你好！" +
//                    email + "提交了”" + processName + "“申请，需要处理，请尽快登录系统完成审批。感谢您的配合！");
//            rocketMQTemplate.convertAndSend(String.format("%s:%s", topic, "TAG_ACTIVITI_TASK_REMIND"), jsonObject);
//        } catch (Exception e) {
//            log.warn("审批提醒 Exception {}", e.getMessage());
//        }
//    }
//
//
//}
